package com.cy.java.api.reflect;

import java.io.File;
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;

public class PackgeTests {
    public static void main(String[] args) {
        //获取字节码对象
        Class<PackgeTests> c = PackgeTests.class;
        //获取类所在的包对象
        Package aPackage = c.getPackage();
        //具体包名
        String name = aPackage.getName();
        System.out.println(name);
        //将包结构转换为目录结构
        String dirName = name.replace(".", "/");
        System.out.println(dirName);
        //通过类加载器获取dirName对应的绝对路径
        URL url=ClassLoader.getSystemClassLoader().getResource(dirName);

        System.out.println(url);
        //获取路径对应的文件对象
        File file=new File(url.getPath());
        //获取目录名
        String[] list = file.list();
        for (String f:list)
            System.out.println(f);
    }
}
